<template>
	<page-meta :page-style="'overflow:' + (show ? 'hidden' : 'visible')"></page-meta>

	<view>
		<view class="top" :style="`padding-top: ${$Height() - 30}px;`">
			<view class="top_box">
				<view class="top_box_left">
					<image class="top_box_left_img" src="/static/30.png" mode="" @click="$fh"></image>
					<view class="top_box_left_box" @click="to_index">
						<image class="top_box_leftt_box_img" src="/static/83.png" mode=""></image>
						返回用户端
					</view>
				</view>
				<view class="top_box_title">我的房源</view>
				<view class="top_box_right" :style="`width: ${$Width() + 15}px;`"></view>
			</view>
		</view>
		<view class="top_img"></view>
		<view class="box">
			<view class="list" v-for="(item, index) in list" :key="index">
				<view class="list_top">
					<image class="list_top_img" :src="item.photo" mode=""></image>
					<view class="list_top_zw_btn">
						<view class="btn1">浏览：{{ item.liulan }}人</view>
						<view class="btn2">
							<image class="btn2_img" src="/static/5.png" mode=""></image>
							<view class="btn2_text">{{ item.xingji || 0 }}</view>
						</view>
					</view>
				</view>

				<view class="list_box">
					<view class="list_box_title">{{ item.title }}</view>
					<view class="list_box_text">
						<view class="list_box_text_nr">
							{{ item.czleixing }}·{{ item.shi }}室{{ item.ting }}厅·{{ item.shuliang }}床·宜住{{ item.renshu }}人
						</view>
						<view class="list_box_text_nr">
							<image class="list_box_text_nr_img" src="/static/51.png" mode=""></image>
							{{ item.area }}
						</view>
					</view>
					<view class="list_box_btn">
						<view class="list_box_btn_left">
							<view class="list_box_btn_left_nr" v-for="(ttem, idx) in item.shebeis" :key="idx">{{ ttem }}</view>
						</view>
						<view class="list_box_btn_right">
							<view class="list_box_btn_right_left">
								<view>
									<span class="span1">¥</span>
									<span class="span2">{{ item.price }}</span>
									<span class="span3">/晚</span>
								</view>
								<span class="span5" v-if="item.zjitian">连住特惠</span>
							</view>
						</view>
					</view>

					<view class="list_btn">
						<view class="list_btn_nr" @click="del(item.id, index)">
							<image class="list_btn_nr_img" src="/static/89.png" mode=""></image>
							删除
						</view>
						<view class="list_btn_nr" @click="to_posts(item.id)">
							<image class="list_btn_nr_img" src="/static/90.png" mode=""></image>
							编辑
						</view>
						<view class="list_btn_nr" @click="to_appraise_list(item.id)">
							<image class="list_btn_nr_img" src="/static/91.png" mode=""></image>
							评价
						</view>
						<view class="list_btn_nr" @click="to_calendar(item.id)">
							<image class="list_btn_nr_img" src="/static/92.png" mode=""></image>
							预订
						</view>
						<view class="list_btn_nr list_btn_nr_x btn1" v-if="item.type == 0" @click="sj(item.id, index)">上架</view>
						<view class="list_btn_nr list_btn_nr_x btn2" v-if="item.type == 1" @click="xj(item.id, index)">下架</view>
					</view>
				</view>
			</view>
		</view>

		<view class="btn">
			<view class="btn_box">
				<view class="btn_box_right" @click="to_posts(0)">发布房源</view>
			</view>
		</view>
		<TabBar :type="2" :index="3" :bd="1"></TabBar>
	</view>
</template>

<script setup>
	import { useCityStore } from '@/utils/cityStore.js'
	const cityStore = useCityStore()
	const http = inject('$http')
	let list = ref([])

	const sj = (id, index) => {
		http.post('/srapi/keyuan/shangjia', { id: id }).then((res) => {
			console.log('上架', res)
			uni.showToast({
				mask: true,
				title: res.msg,
				icon: 'none',
				duration: 500
			})
			list.value[index].type = 1
		})
	}
	const xj = (id, index) => {
		http.post('/srapi/keyuan/xiajia', { id: id }).then((res) => {
			console.log('下架', res)
			uni.showToast({
				mask: true,
				title: res.msg,
				icon: 'none',
				duration: 500
			})
			list.value[index].type = 0
		})
	}

	const del = (id, index) => {
		uni.showModal({
			title: '提示',
			content: '确定删除该房源么',
			success: function (res) {
				if (res.confirm) {
					http.post('/srapi/keyuan/scfangyuan', { id: id }).then((res) => {
						console.log('用户点击确定', res)
						uni.showToast({
							mask: true,
							title: res.msg,
							icon: 'none',
							duration: 500
						})
						list.value.splice(index, 1)
					})
				} else if (res.cancel) {
					console.log('用户点击取消')
				}
			}
		})
	}
	const indexlist = async () => {
		await http.post('/srapi/keyuan/fangyuan').then((res) => {
			console.log('返回值', res.data)
			list.value = res.data
		})
	}

	onShow(async () => {
		console.log('页面刷新')
		await indexlist()
	})
	onLoad(async (option) => {
		console.log('接收传参:', option)
		await cityStore.init()
	})
	const to_index = () => {
		uni.switchTab({
			url: '/pages/index/index'
		})
	}
	const to_posts = (id) => {
		uni.navigateTo({
			url: '/pages_B/posts/posts?id=' + id
		})
		console.log('发布房源')
	}

	const to_appraise_list = (id) => {
		uni.navigateTo({
			url: '/pages_B/appraise_list/appraise_list?id=' + id
		})
	}
	const to_calendar = (id) => {
		uni.navigateTo({
			url: '/pages_B/calendar/calendar?id=' + id
		})
	}
</script>

<style lang="less" scoped>
	.top {
		position: sticky;
		left: 0;
		top: 0;
		z-index: 9;
		width: 750rpx;
		box-sizing: border-box;
		padding: 30rpx;
		background: linear-gradient(0deg, #e3f0fa 0%, #c0e6fc 100%);
		.top_box {
			position: relative;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding-bottom: 10rpx;
			.top_box_left {
				display: flex;
				align-items: center;
				position: relative;
				z-index: 2;
				.top_box_left_img {
					width: 17rpx;
					height: 30rpx;
					margin-right: 30rpx;
				}
				.top_box_left_box {
					display: flex;
					justify-content: center;
					align-items: center;
					width: 190rpx;
					height: 60rpx;
					background: rgba(255, 255, 255, 0.8);
					border: 1rpx solid #d4d4d4;
					border-radius: 31rpx;
					font-size: 24rpx;
					font-weight: 500;
					color: #000000;
					letter-spacing: -0.43rpx;
					.top_box_leftt_box_img {
						width: 26rpx;
						height: 26rpx;
						margin-right: 5rpx;
					}
				}
			}
			.top_box_title {
				position: absolute;
				z-index: 1;
				width: 750rpx;
				left: -30rpx;
				flex: 1;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 32rpx;
				font-weight: 500;
				color: #000000;
			}
		}
	}
	.top_img {
		width: 750rpx;
		height: 320rpx;
		position: fixed;
		top: 0;
		left: 0;
		z-index: -1;
		background: linear-gradient(0deg, #f4f5f9 0%, #c0e6fc 100%);
	}
	.box {
		padding: 0 30rpx 30rpx;
	}
	.list {
		width: 690rpx;
		border-radius: 12rpx;
		margin-bottom: 30rpx;
		.list_top {
			width: 690rpx;
			height: 460rpx;
			position: relative;
			.list_top_img {
				width: 690rpx;
				height: 460rpx;
			}
			.list_top_zw_top {
				width: 690rpx;
				box-sizing: border-box;
				position: absolute;
				left: 0;
				top: 0;
				padding: 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				.img1 {
					width: 135rpx;
					height: 40rpx;
				}
				.img2 {
					width: 40rpx;
					height: 38rpx;
				}
			}
			.list_top_zw_btn {
				width: 690rpx;
				box-sizing: border-box;
				position: absolute;
				left: 0;
				bottom: 0;
				padding: 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				.btn1 {
					padding: 8rpx 15rpx;
					background: rgba(0, 0, 0, 0.6);
					border-radius: 17rpx;
					font-size: 20rpx;
					font-weight: 500;
					color: #ffffff;
				}
				.btn2 {
					width: 106rpx;
					position: relative;
					.btn2_img {
						width: 106rpx;
						height: 34rpx;
						border-radius: 17rpx;
						position: absolute;
						z-index: 1;
					}
					.btn2_text {
						font-size: 24rpx;
						font-weight: 500;
						text-align: left;
						color: #ffffff;
						position: relative;
						z-index: 2;
						padding-left: 20rpx;
					}
				}
			}
		}
		.list_box {
			border-radius: 0 0 12rpx 12rpx;
			background: #ffffff;
			padding: 30rpx;
			.list_box_title {
				font-size: 28rpx;
				font-weight: 700;
				color: #000000;
				margin-bottom: 20rpx;
			}
			.list_box_text {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 20rpx;
				.list_box_text_nr {
					display: flex;
					align-items: center;
					font-size: 24rpx;
					font-weight: 500;
					color: #787878;
					.list_box_text_nr_img {
						width: 21rpx;
						height: 24rpx;
						margin-right: 10rpx;
					}
				}
			}

			.list_box_btn {
				display: flex;
				justify-content: space-between;
				align-items: center;
				.list_box_btn_left {
					display: flex;
					justify-content: flex-start;
					align-items: center;
					.list_box_btn_left_nr {
						background: #ffffff;
						border: 1rpx solid #b6b6b6;
						border-radius: 6rpx;
						font-size: 20rpx;
						font-weight: 500;
						color: #656565;
						padding: 5rpx;
						margin-right: 10rpx;
					}
				}
				.list_box_btn_right {
					display: flex;
					justify-content: space-between;
					align-items: center;
					.list_box_btn_right_left {
						display: flex;
						align-items: flex-end;
						.span1 {
							font-size: 24rpx;
							font-weight: 500;
							color: #e93424;
						}
						.span2 {
							font-size: 36rpx;
							font-weight: 700;
							color: #e93424;
						}
						.span3 {
							font-size: 20rpx;
							font-weight: 700;
							color: #e93424;
						}
						.span4 {
							font-size: 24rpx;
							font-weight: 500;
							text-decoration: line-through;
							color: #787878;
							margin-left: 10rpx;
						}
						.span5 {
							background: #ffffff;
							border: 1rpx solid #e93424;
							border-radius: 6rpx;
							padding: 5rpx;
							font-size: 20rpx;
							font-weight: 500;
							color: #e93424;
							margin-left: 10rpx;
						}
					}
				}
			}
		}
		.list_btn {
			margin-top: 20rpx;
			padding-top: 20rpx;
			border-top: 1px solid #e4e5e9;
			display: flex;
			justify-content: space-between;
			align-items: center;
			.list_btn_nr {
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 24rpx;
				font-weight: 500;
				color: #000000;
				.list_btn_nr_img {
					width: 28rpx;
					height: 28rpx;
					margin-right: 10rpx;
				}
			}
			.list_btn_nr_x {
				width: 160rpx;
				height: 62rpx;
				border-radius: 12rpx;
				font-size: 28rpx;
				font-weight: 700;
				color: #ffffff;
			}
			.btn1 {
				background: #3475f3;
			}
			.btn2 {
				background: #f33434;
			}
		}
	}

	.btn {
		margin-top: 60rpx;
		height: 115rpx;
		padding-bottom: calc(constant(safe-area-inset-bottom));
		padding-bottom: calc(env(safe-area-inset-bottom));
		.btn_box {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 750rpx;
			box-sizing: border-box;
			background: #fff;
			padding: 15rpx 30rpx 115rpx;
			padding-bottom: calc(115rpx + constant(safe-area-inset-bottom));
			padding-bottom: calc(115rpx + env(safe-area-inset-bottom));
			display: flex;
			justify-content: space-between;
			align-items: center;
			box-shadow: 0 -4rpx 12rpx rgba(0, 0, 0, 0.05);
			z-index: 20;
			.btn_box_left {
				width: 223rpx;
				height: 78rpx;
				background: #ffffff;
				border: 2rpx solid #2468fb;
				border-radius: 41rpx;
				font-size: 28rpx;
				font-weight: 700;
				color: #2468fb;
				display: flex;
				justify-content: center;
				align-items: center;
				margin-right: 21rpx;
				.btn_box_left_img {
					width: 32rpx;
					height: 32rpx;
					margin-right: 10rpx;
				}
			}
			.btn_box_right {
				display: flex;
				justify-content: center;
				align-items: center;
				background: #2468fb;
				border: 2rpx solid #2468fb;
				height: 78rpx;
				border-radius: 39rpx;
				flex: 1;
				font-size: 28rpx;
				font-weight: 700;
				color: #ffffff;
			}
		}
	}

	//
</style>
